<template>
	<view>
		<view class="bus_info tp-w690">
			<view class="info_top-wrap">
				<view class="date">
					<text class="type">班车</text>
					发车时间：{{dateInfo.departureTime}}
				</view>
				<text class="tp-red">{{dateInfo.ticketState == 0?'未核销':dateInfo.ticketState == 1?'已核销':dateInfo.ticketState == 2?'已退票':dateInfo.ticketState == 3?'已失效':dateInfo.ticketState == 4?'已改签':''}}</text>
			</view>
			<view class="info_content-wrap" @click="handleGoBusOrderDetail(dateInfo)">
				<view class="shift-wrap">
					<view class="from">
						<text class="time">{{dateInfo.startTime}}</text>
						<text class="address">{{dateInfo.place}}</text>
					</view>
					<view class="bus_type-wrap">
						<text class="but_type">{{dateInfo.shiftsCartype}}</text>
						<view class="dack"></view>
						<text class="duration">历时{{dateInfo.travelTime}}分钟</text>
					</view>
					<view class="to">
						<text class="time">{{dateInfo.arriveTime}}</text>
						<text class="address">{{dateInfo.destination}}</text>
					</view>
				</view>
				<view class="site-wrap">
					<view class="site">
						<text class="name">{{dateInfo.passengerName}}</text><text v-if="dateInfo.seatNumber">座位：{{dateInfo.seatNumber || ''}}</text>
					</view>
					<view class="service" v-if="dateInfo.goTransferId != -1" @click.stop="handleGoPickupDetail(dateInfo.goTransferId)">接站服务</view>
					<view class="service" v-if="dateInfo.backTransferId != -1" @click.stop="handleGoPickupDetail(dateInfo.backTransferId)">送站服务</view>
				</view>

			</view>
			<view class="order_info-wrap" v-if="curNavbar.alias==='noTravel' || dateInfo.status != 1">
				<view class="order_num"></view>
				<view class="btns">
					<view v-if="dateInfo.status == 1 && (dateInfo.ticketState == 0 || dateInfo.ticketState == 4) && dateInfo.isGaiQian == 1" class="btn cancle" @click="handleRefund">退票</view>
					<view v-if="dateInfo.status != 1" class="btn cancle" @click="handleDel">删除车票</view>
					<view v-if="dateInfo.isGaiQian == 1 && dateInfo.ticketState == 0 && dateInfo.status == 1" class="btn edit" @click="handleChange">改签</view>
					<view v-if="dateInfo.isGaiQian == 0" class="btn disable">已改签</view>
					<view v-if="(dateInfo.status == 1 || dateInfo.status == 2) && (dateInfo.ticketState == 0 || dateInfo.ticketState == 3)" class="btn cancle" @click="handleShowCode">二维码检票</view>
				</view>
			</view>
		</view>



	</view>
</template>

<script>
	import calendar from '@/components/tp-calendar/util.js'
	export default {
		components: {},
		props: {
			dateInfo: {
				type: Object,
				default () {
					return {}
				}
			},
			curNavbar: {
				type: [Object, Boolean],
				default () {
					return false
				}
			},
			hideBtn: {
				type: Boolean,
				default () {
					return false
				}
			},
			delayDay: {
				type: Number,
				default () {
					return 0
				}
			}
		},
		data() {
			return {

			};
		},
		mounted() {

		},
		methods: {
			handleShowCode() {
				uni.$emit('showCode', this.dateInfo)
			},
			handleGoBusOrderDetail(data) {
				let {
					ciracuitType
				} = data // 线路类型（0单程1往返）
				if (ciracuitType == 0) { // 单程
					uni.navigateTo({
						url: '/pagesUser/order/bus.orderDetail?id=' + data.orderNo + '&hideBtn=true&status=' +
							data.status
					});
				} else if (ciracuitType == 1) { // 往返程
					uni.navigateTo({
						url: '/pagesUser/order/bus.orderDetail?id=' + data.orderNo + '&hideBtn=true&toAndFor=true' +
							'&status=' + data.status
					});
				}
				// uni.navigateTo({
				// 	url: '/pagesUser/order/bus.orderDetail?id=' + this.dateInfo.orderNo + '&hideBtn=' + this.hideBtn
				// });
			},
			// handleChange() { // 改签
			// 	uni.$emit('Change', this.dateInfo)
			// },

			// 改签
			handleChange() {
				let choosedDateObj = this.$store.getters.getHomeChoosedDateObj;
				const curDay = calendar.getDateObj() // 当前日期
				// console.log('curDay' + curDay);
				const delayDateObj = calendar.getBeforeDate(curDay.full, this.delayDay)
				let dateObj = calendar.getDateObj(delayDateObj)
				// console.log(' dateObj.month', dateObj.month.replace(/\b(0)/gi, ''));

				const m = dateObj.month.replace(/\b(0)/gi, '')
				const d = dateObj.day.replace(/\b(0)/gi, '')

				if (!choosedDateObj.back_full) { // 如果没有选择日期，
					this.$store.commit('upHomeChoosedDateObj', {
						back: m + '月' + d + '日',
						back_full: dateObj.full,
						back_obj: dateObj,
						go: m + '月' + d + '日',
						go_full: dateObj.full,
						go_obj: dateObj
					});
				}
				uni.navigateTo({
					url: '/pagesTravel/travelBusList?delayDay=' + this.delayDay + '&ticketId=' + this.dateInfo.id
				})

			},
			handleRefund() { // 退票
				uni.$emit('Refund', this.dateInfo)
			},
			handleDel() { // 删除车票
				uni.$emit('delPiao', this.dateInfo)
			},

			handleGoPickupDetail(id) { // 跳转到接送服务详情
				uni.navigateTo({
					url: '/pagesUser/pickupDetail?id=' + id
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bus_info {
		background: #fff;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-bottom: 20rpx;

		.info_top-wrap {
			height: 80rpx;
			display: flex;
			align-items: center;
			font-size: 26rpx;
			justify-content: space-between;
			padding: 0 20rpx;

			.date {
				color: #666;
				display: flex;
				align-items: center;

				.type {
					display: inline-block;
					width: 66rpx;
					height: 40rpx;
					line-height: 40rpx;
					text-align: center;
					background-color: #FFF2E0;
					color: $yellow;
					font-size: 22rpx;
					margin-right: 20rpx;
					border-radius: 8rpx;
				}
			}
		}

		.info_content-wrap {
			display: flex;
			flex-direction: column;
			padding: 40rpx;
			border-top: 1px solid #EBEBEB;
			border-bottom: 1px solid #EBEBEB;

			.shift-wrap {
				display: flex;
				flex: 1;
				justify-content: space-between;

				.from,
				.to {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					line-height: 1;
					height: 100rpx;

					.time {
						font-size: 48rpx;
						font-weight: bold;
					}

					.address {
						font-size: 32rpx;
					}
				}

				.to {
					text-align: right;
				}

				.bus_type-wrap {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					font-size: 24rpx;
					color: #666;
					height: 100rpx;

					.dack {
						width: 170rpx;
						background-color: #ccc;
						height: 6rpx;
						position: relative;

						&::before {
							content: '';
							position: absolute;
							width: 35rpx;
							height: 6rpx;
							top: -11rpx;
							right: -7rpx;
							background-color: #ccc;
							transform: rotate(45deg);
						}
					}
				}
			}

			.site-wrap {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 39rpx;
				line-height: 1;

				.site {
					.name {
						margin-right: 40rpx;
					}
				}

				.service {
					color: $blue;
				}
			}
		}

		.order_info-wrap {
			height: 95rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #666;
			padding: 0 20rpx;

			.order_num {
				font-size: 26rpx;
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.btn {
					border-radius: 12rpx;
					padding: 0 15rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: center;
					min-width: 78rpx;
					font-size: 28rpx;

					&.cancle {
						border: 1px solid $blue;
						color: $blue;
						margin-left: 20rpx;
					}

					&.edit {
						border: 1px solid $yellow;
						color: $yellow;
						margin-left: 20rpx;
					}

					&.disable {
						background-color: #ebebeb;
						margin-left: 20rpx;
					}
				}
			}
		}
	}
</style>
